package com.gaoyang.util;

import com.gaoyang.domain.DianPingUser;

import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class HttpUtils4MeiTuanBlack {

	public static List<String> returnCookies(String address, Map<String, String> paramMap) {
		String paramUrl = "";
		StringBuffer strbuffer = new StringBuffer();
		List<String> result = new ArrayList();
		BufferedReader in = null;
		try {

			if ((paramMap != null) && (paramMap.size() > 0)) {
				for (Map.Entry entry : paramMap.entrySet()) {
					String key = String.valueOf(entry.getKey());
					String value = String.valueOf(entry.getValue());
					strbuffer.append(key);
					strbuffer.append("=");
					strbuffer.append(value);
					strbuffer.append("&");
				}
				paramUrl = strbuffer.toString();
				paramUrl = paramUrl.substring(0, paramUrl.length() - 1);
			}
			String url = address + "?" + paramUrl;
			URL realUrl = new URL(url);

			URLConnection connection = realUrl.openConnection();
			connection.setRequestProperty("notitlebar","1");
			connection.setRequestProperty("env","mt");
			connection.setRequestProperty("utm_source","mt_search");
			connection.setRequestProperty("ct_poi","_b100002");
			connection.setRequestProperty("uuid", paramMap.get("uuid"));
			connection.setRequestProperty("version_name","11.12.405");
			connection.setRequestProperty("utm_term","11.12.405");
			connection.setRequestProperty("utm_content", paramMap.get("uuid"));
			connection.setRequestProperty("userid", paramMap.get("userid"));
			connection.setRequestProperty("utm_medium","iphone");
			connection.setRequestProperty("utm_campaign","AgroupBgroupD200Ghomepage_searchH0");
			connection.setRequestProperty("f","iphone");
			connection.setRequestProperty("msid","AA48AE3C-B857-43D3-9ED7-5DC49930BE2B1633615684654665");

			connection.connect();
			Map<String, List<String>> cookies = connection.getHeaderFields();
			result = cookies.get("Set-Cookie");

		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (in != null)
					in.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		} finally {
			try {
				if (in != null)
					in.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return result;
	}

}
